Completed
Push — master ( e88c19...17669b )
by Rain
03:00
created

Jassl.js ➔ ... ➔ ???   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
c 1
b 1
f 0
nc 1
nop 2
dl 0
loc 17
rs 9.4285
1
2
import window from 'window';
3
import Promise from 'Promise';
4
5
// let rainloopCaches = window.caches && window.caches.open ? window.caches : null;
6
7
/**
8
 * @param {src} src
9
 * @param {boolean} async = false
10
 * @returns {Promise}
11
 */
12
export function jassl(src, async = false) {
0 ignored issues
show
Unused Code introduced by
The parameter async is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter src is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
13
14
	if (!Promise || !Promise.all)
15
	{
16
		throw new Error('Promises are not available your environment.');
17
	}
18
19
	if (!src)
0 ignored issues
show
Best Practice introduced by
If you intend to check if the variable src is declared in the current environment, consider using typeof src === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
20
	{
21
		throw new Error('src should not be empty.');
22
	}
23
24
	return new Promise((resolve, reject) => {
25
26
		const element = window.document.createElement('script');
27
28
		element.onload = () => {
29
			resolve(src);
30
		};
31
32
		element.onerror = () => {
33
			reject(new Error(src));
34
		};
35
36
		element.async = true === async;
37
		element.src = src;
38
39
		window.document.body.appendChild(element);
40
	})/* .then((s) => {
41
42
		const found = s && rainloopCaches ? s.match(/rainloop\/v\/([^\/]+)\/static\//) : null;
43
		if (found && found[1])
44
		{
45
			rainloopCaches.open('rainloop-offline-' + found[1]).then(
46
				(cache) => cache.add(s)
47
			).catch(() => {
48
				rainloopCaches = null;
49
			});
50
		}
51
52
		return s;
53
	})*/;
54
}
55